package com.txf.simple.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

/**
 * @author txf
 * @Title
 * @package com.txf.simple.ui.widget
 * @date 2017/2/13 0013
 */

public class NoticeWidget extends LinearLayout {
    TextView textView1,
            textView2,
            textView3;
    List<String> mDatas;

    public NoticeWidget(Context context) {
        super(context);
        init();
    }

    public NoticeWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public NoticeWidget(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setOrientation(VERTICAL);
    }

    private TextView buildView(Object tag) {
        TextView view = new TextView(getContext());
        view.setTag(tag);
        view.setTextSize(16);
        view.setGravity(Gravity.CENTER);
        return view;
    }

    public void setData(List<String> datas) {
        if (datas == null || datas.size() == 0)
            return;
        mDatas = datas;
        initViews();
        intdata();
    }

    private void intdata() {
        if (mDatas.size() < 2) {
            textView1.setText(mDatas.get(0));
            return;
        }
        if (mDatas.size() < 3) {
            textView1.setText(mDatas.get(0));
            textView2.setText(mDatas.get(1));
        }else {
            textView1.setText(mDatas.get(0));
            textView2.setText(mDatas.get(1));
            textView3.setText(mDatas.get(2));
            startPlay();
        }
    }
    private void startPlay() {


    }
    private void initViews() {
        for (int i = 0; i < 3; i++) {
            addView(buildView(i), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        }
        textView1 = (TextView) findViewWithTag(0);
        textView2 = (TextView) findViewWithTag(1);
        textView3 = (TextView) findViewWithTag(2);
    }
}
